package com.company._2Field;

import com.company._1class.Person;

import java.lang.reflect.Field;

public class TestFiledDemo {
    public static void main(String[] args) throws NoSuchFieldException {

        Class c = Person.class;

        //得到所有公开的字段
        Field[] fields1 = c.getFields();
        for (Field f : fields1) {
            System.out.println(f);
        }
        //得到所有本类的字段
        Field[] fields2 = c.getDeclaredFields();
        for (Field f : fields2) {
            System.out.println(f);
        }

        //得到公开的某个属性
        Field f1 = c.getField("nickName");
        //得到本身类的属性
        Field f2 = c.getDeclaredField("age");
        f2.setAccessible(true);

    }
}
